import moment from 'moment'

export const FormUtils = {
  setFieldsValue(_form, model) {
    //获取所有表单所需的对象
    var formFields = _form.getFieldsValue()
    //把用户获取的对象设置到表单所需对象中
    for (var key in formFields) {
      if (model[key] == null) continue
      if (key.indexOf('date') != -1) {
        formFields[key] = moment(model[key], "YYYY-MM-DD HH:mm:ss")
      }else if ((model[key].constructor == Object)
        || (model[key].constructor == Array)
        || (model[key].constructor == Boolean)
      ) {
        formFields[key] = model[key]
      }else {
        formFields[key] = model[key].toString()
      }
    }
    _form.setFieldsValue(formFields)
  },
}